import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import { ArcoResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src')
      }
    },
    plugins: [
      vue(),
      // 将 unplugin-vue-components 放在渲染器配置中
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: 'less'
          }),
          ArcoResolver({
            resolveIcons: true,
            sideEffect: true,
            // 使用 prefix 选项而不是 alias
            prefix: 'Arco'
          })
        ],
        dts: resolve('src/renderer/src/components.d.ts') // 明确指定类型文件路径
      })
    ],
    // CSS 配置也应该在渲染器中
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true,
          modifyVars: {
            // 可在此配置主题变量
          }
        }
      }
    }
  }
})
